package com.zcw.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class CommUtils {
	/**
	 * @project xsgl
	 * @project com.sgcc.xsgl.statix.common
	 * @Title: print
	 * @Description: 统一打印控制台方法
	 * @author zhangcunwei
	 * @createDate 2019-9-16 下午4:25:55
	 * @param msg 打印信息
	 * @param b   打印之前是否输出一行空白
	 */
	public static void println(Object msg) {
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
		if (isEmpty(msg)) {
			System.out.println();
		} else {
			System.out.printf("[%s] %s\n", date, msg);
		}
	}

	public static void println() {
		println("");
	}

	public static void printf(String format, Object... args) {
		String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
		System.out.printf("[" + date + "] " + format + "\n", args);
	}

	public static boolean isEmpty(Object obj) {
		if (obj == null) {
			return true;
		}
		String str = obj.toString();
		str = str.trim();
		if ("".equalsIgnoreCase(str) || "null".equalsIgnoreCase(str) || "undefined".equalsIgnoreCase(str)) {
			return true;
		}
		return false;
	}

	public static void main(String[] args) {
		printf("123");
		printf("123");
	}

	public static int objToInt(Object obj) {
		if (CommUtils.isEmpty(obj)) {
			return 0;
		}
		return Integer.parseInt(obj.toString());
	}
}
